package com.amc.controllers;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.amc.dto.CommentView;
import com.amc.dto.FoodView;
import com.amc.entity.FoodType;
import com.amc.service.ICommentService;
import com.amc.service.IFoodService;

@Controller
@RequestMapping("/food")
public class FoodListController {
	private IFoodService serviceFood;

	@Resource(name = "foodService")
	public void setService(IFoodService serviceFood) {
		this.serviceFood = serviceFood;
	}

	private ICommentService serviceComment;

	@Resource(name = "commentService")
	public void setServiceComment(ICommentService serviceComment) {
		this.serviceComment = serviceComment;
	}

	@RequestMapping(value = "/foodtypelist", method = { RequestMethod.GET })
	@ResponseBody
	public List<FoodType> initFoodTypeList(String merchantId) {
		return serviceFood.queryFoodTypeByMId(merchantId);
	}

	@RequestMapping(value = "/foodlist", method = { RequestMethod.GET })
	@ResponseBody
	public List<FoodView> initFoodList(String merchantId) {
		return serviceFood.queryFoodByMId(merchantId);
	}

	@RequestMapping(value = "/commentlist", method = { RequestMethod.GET })
	@ResponseBody
	public List<CommentView> initCommentList(String merchantId) {
		return serviceComment.showComment(merchantId);
	}

	@RequestMapping(value = "/updatefoodlist", method = { RequestMethod.GET })
	@ResponseBody
	public List<FoodView> updateFoodList(String merchantId, String foodTypeId) {
		return serviceFood.queryFoodByFoodType(merchantId, foodTypeId);
	}

	@RequestMapping(value = "/detail", method = { RequestMethod.GET })
	@ResponseBody
	public FoodView foodDetail(String foodId) {
		return serviceFood.queryFood(foodId);
	}
	
	@RequestMapping(value = "/search", method = { RequestMethod.GET })
	@ResponseBody
	public List<FoodView> searchFoodList(String keyword) throws UnsupportedEncodingException {
		keyword = new String(keyword.getBytes("ISO-8859-1"), "UTF-8");
		List<FoodView> list = new ArrayList<>();
		list = serviceFood.queryFoodByKeyWord(keyword);
		return list;
	}
}
